/**
 * 请求模块
 */
import axios from 'axios'
import store from '@/store'
import JSONbig from 'json-bigint'


const request = axios.create({
    baseURL: "http://localhost:8080",
    transformResponse: [function (data) {
      try {
        return JSONbig.parse(data)
      } catch(err) {
        console.log('转换失败');
        return data
      }
    }]
})
export default request
//请求拦截器
request.interceptors.request.use(function (config) {
    // 在发送请求之前做些什么3
    console.log('123');  
    console.log(config);
    const { user } = store.state
    if(user) {
        config.headers.Authorization = `Bearer ${store.state.user.token}`
    }
    return config


  }, function (error) {
    // 对请求错误做些什么
    return Promise.reject(error)
  })



//相应拦截器
